package com.gylang.print.richtext.component;

import cn.hutool.core.util.StrUtil;
import com.gylang.print.pdf.util.PdfUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author gylang
 * data 2021/7/13
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BaseRichText extends BaseRich {

	private String text;

	public BaseRichText() {
	}

	public BaseRichText(RichBox box) {
		setBox(box);
	}

	@Override
	public float width() {
		if (StrUtil.isEmpty(text)) {
			return 0;
		}
		return PdfUtil.getTextLength(getBox().getFont(get(FONT)), getNullDefault(FONT_SIZE, getBox().getFontSize()), text);
	}

	@Override
	public float height() {
		return getNullDefault(FONT_SIZE, getBox().getFontSize());
	}

	@Override
	public boolean notFillBr() {
		return false;
	}
}
